package com.cmnit.analysis.util

import java.util.Date

object ServiceUtil {

  /**
   * 获取上一小时账期时间
   *
   * @return
   */
  def getLastHourAcctTime(date: Date): String = {
    val year = DateUtil.getLastHourOfYear(date)
    val month = DateUtil.getLastHourOfMonth(date)
    val day = DateUtil.getLastHourOfDay(date)
    val hour = DateUtil.getLastHour(date)
    year + month + day + hour
  }

  /**
   * 获取账期时间的SQL拼接
   *
   * @return
   */
  def getAcctInfo(acctTime: String): String = {
    // 拼接年份
    var sql = "year='" + acctTime.substring(0, 4) + "' "
    // 拼接月份
    if (acctTime.length >= 6) {
      sql += "and month='" + acctTime.substring(4, 6) + "' "
    }
    // 拼接日期
    if (acctTime.length >= 8) {
      sql += "and day='" + acctTime.substring(6, 8) + "' "
    }
    // 拼接小时
    if (acctTime.length >= 10) {
      sql += "and hour='" + acctTime.substring(8, 10) + "' "
    }
    sql
  }
}
